package cn.tedu.property_management_system.service.Impl;

import cn.tedu.property_management_system.entity.Home;
import cn.tedu.property_management_system.mapper.HomeMapper;
import cn.tedu.property_management_system.service.IHomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class HomeServiceImpl implements IHomeService {

    @Autowired
    private HomeMapper homeMapper;

    private List<Integer> getlist(List<Home> list) {

        Map<String, Integer> map = new HashMap<>();
        Integer sum1 = 0;
        Integer sum2 = 0;
        Integer sum3 = 0;
        Integer sum4 = 0;
        Integer sum5 = 0;
        Integer sum6 = 0;
        Integer sum7 = 0;
        for (Home home : list) {
            if (home == null) {
                continue;
            }
            Long times = home.getTime1();
            if (times == null) {
                continue;
            }
            Long time = times % 7 * 24 * 60 * 60 * 1000;
            if (time < 1 * 24 * 60 * 60 * 1000) {
                sum1 = sum1 + 1;
                map.put("Mon", sum1);
            } else if (time < 2 * 24 * 60 * 60 * 1000) {
                sum2 = sum2 + 1;
                map.put("Tue", sum2);
            } else if (time < 3 * 24 * 60 * 60 * 1000) {
                sum3 = sum3 + 1;
                map.put("Wed", sum3);
            } else if (time < 4 * 24 * 60 * 60 * 1000) {
                sum4 = sum4 + 1;
                map.put("Thu", sum4);
            } else if (time < 5 * 24 * 60 * 60 * 1000) {
                sum5 = sum5 + 1;
                map.put("Fri", sum5);
            } else if (time < 6 * 24 * 60 * 60 * 1000) {
                sum6 = sum6 + 1;
                map.put("Sat", sum6);
            } else if (time < 7 * 24 * 60 * 60 * 1000) {
                sum7 = sum7 + 1;
                map.put("Sun", sum7);
            }
        }
        //'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'

        List<Integer> integers = new ArrayList<>();
//        map.forEach((k,v)->{
//            integers.add(v);
//        });
//
        integers.add(map.get("Mon")==null?0:map.get("Mon"));
        integers.add(map.get("Tue")==null?0:map.get("Tue"));
        integers.add(map.get("Wed")==null?0:map.get("Wed"));
        integers.add(map.get("Thu")==null?0:map.get("Thu"));
        integers.add(map.get("Fri")==null?0:map.get("Fri"));
        integers.add(map.get("Sat")==null?0:map.get("Sat"));
        integers.add(map.get("Sun")==null?0:map.get("Sun"));

        return integers;
    }


    @Override
    public List<Integer> getBuilding() {
        List<Home> list = homeMapper.building();
        return getlist(list);
    }

    @Override
    public Integer getBuildings() {
        return homeMapper.buildingBumber();
    }

    @Override
    public List<Integer> getHouse() {
        List<Home> list = homeMapper.house();

        return getlist(list);
    }

    @Override
    public Integer getHouses() {
        return homeMapper.houseBumber();
    }

    @Override
    public List<Integer> getMeter() {
        List<Home> list = homeMapper.meter();
        return getlist(list);
    }

    @Override
    public Integer getMeters() {
        return homeMapper.meterBumber();
    }

    @Override
    public List<Integer> getOwner() {
        List<Home> list = homeMapper.owner();
        return getlist(list);
    }

    @Override
    public Integer getOwners() {
        return homeMapper.ownerBumber();
    }

    @Override
    public List<Integer> getParking() {
        List<Home> list = homeMapper.parking();

        return getlist(list);
    }

    @Override
    public Integer getParkings() {
        return homeMapper.parkingBumber();
    }



    @Override
    public Integer getCar() {
        return homeMapper.getCar();
    }

    @Override
    public Integer getProperty() {
        return homeMapper.getProperty();
    }

    @Override
    public Integer getComplaint() {
        return homeMapper.getComplaint();
    }

    @Override
    public Integer getRepair() {
        return homeMapper.getRepair();
    }
}
